﻿using ImageMagick;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace YYFDebugTools.ViewModels
{
    public class ImageOptionsSetVM : BaseModel
    {
        public ImageOptionsSetVM()
        {
        }
        public bool SetSelectFunc()
        {
            SelectFunc = null;
            if (Func_ChangeType.IsSelect)
            {
                SelectFunc = Func_ChangeType;
            }
            else if (Func_Cut.IsSelect)
            {
                SelectFunc = Func_Cut;
            }
            else if (Func_ReSize.IsSelect)
            {
                SelectFunc = Func_ReSize;
            }
            else if (Func_Blur.IsSelect)
            {
                SelectFunc = Func_Blur;
            }
            else if (Func_Border.IsSelect)
            {
                SelectFunc = Func_Border;
            }
            else if (Func_Compress.IsSelect)
            {
                SelectFunc = Func_Compress;
            }
            else if (Func_Mirro.IsSelect)
            {
                SelectFunc = Func_Mirro;
            }
            else if (Func_Rotate.IsSelect)
            {
                SelectFunc = Func_Rotate;
            }
            return SelectFunc != null;
        }

        private Func_Base? selectfunc;
        public Func_Base? SelectFunc
        {
            get { return selectfunc; }
            set { selectfunc = value; OnPropertyChanged(); }
        }
        public Func_ChangeType Func_ChangeType { get; set; } = new();
        public Func_Cut Func_Cut { get; set; } = new();
        public Func_ReSize Func_ReSize { get; set; } = new();
        public Func_Blur Func_Blur { get; set; } = new();
        public Func_Border Func_Border { get; set; } = new();
        public Func_Compress Func_Compress { get; set; } = new();
        public Func_Mirro Func_Mirro { get; set; } = new();
        public Func_Rotate Func_Rotate { get; set; } = new();
        public Func_WaterMarkImage Func_WaterMarkImage { get; set; }
        public Func_WaterMarkText Func_WaterMarkText { get; set; }
    }

    public abstract class Func_Base : BaseModel
    {
        public Func_Base(string name)
        {
            FuncName = name;
            IsEnable = true;
        }
        public string FuncName { get; set; }

        private bool isselect;
        /// <summary>
        /// 是否选中
        /// </summary>
        public bool IsSelect
        {
            get
            {
                return isselect;
            }
            set
            {
                isselect = value;
                OnPropertyChanged();
            }
        }
        private bool isenable;
        /// <summary>
        /// 是否可以点击
        /// </summary>
        public bool IsEnable
        {
            get { return isenable; }
            set { isenable = value; OnPropertyChanged(); }
        }

        public abstract MagickImage CalImages(MagickImage input);

    }


    public class Func_ChangeType : Func_Base
    {
        public Func_ChangeType() : base("修改格式")
        {
            FileTypes = [
                MagickFormat.Jpg.ToString(),
                MagickFormat.Png.ToString(),
            ];
            outformat = FileTypes[0];
        }
        public List<string> FileTypes { get; set; }
        private string outformat;
        /// <summary>
        /// 文件格式
        /// </summary>
        public string OutFormat
        {
            get { return outformat; }
            set { outformat = value; OnPropertyChanged(); }
        }

        public override MagickImage CalImages(MagickImage input)
        {
            input.Format = Enum.Parse<MagickFormat>(OutFormat);
            return input;
        }
    }
    public class Func_Cut : Func_Base
    {
        public Func_Cut() : base("图片裁剪")
        {
            cutstr = "0,0,0,0";
        }
        private string cutstr;

        public string CutStr
        {
            get { return cutstr; }
            set { cutstr = value; OnPropertyChanged(); }
        }
        public override MagickImage CalImages(MagickImage input)
        {
            //input.Crop(,);
            return input;
        }
    }
    public class Func_ReSize : Func_Base
    {
        public Func_ReSize() : base("修改尺寸")
        {
            ReSizeTemps.Add(new ReSizeTemp("小一寸照片(260x378)"));
            ReSizeTemps.Add(new ReSizeTemp("一寸照片(295x413)"));
            ReSizeTemps.Add(new ReSizeTemp("大一寸照片(390x567)"));
            ReSizeTemps.Add(new ReSizeTemp("两寸照片(413x626)"));
            ReSizeTemps.Add(new ReSizeTemp("中国签证(472x709)"));
            ReSizeTemps.Add(new ReSizeTemp("美国签证(600x600)"));
            ReSizeTemps.Add(new ReSizeTemp("微信头像(640x640)"));
        }
        private ReSizeTemp? selecttemp;

        public ReSizeTemp? SelectResezeTemp
        {
            get
            {
                return selecttemp;
            }
            set
            {
                selecttemp = value;
                OnPropertyChanged();
                if (value != null)
                {
                    this.Width = value.Width;
                    this.Height = value.Height;
                }
            }
        }

        public List<ReSizeTemp> ReSizeTemps { get; set; } = [];
        private int width;

        public int Width
        {
            get { return width; }
            set { width = value; OnPropertyChanged(); }
        }
        private int height;

        public int Height
        {
            get { return height; }
            set { height = value; OnPropertyChanged(); }
        }
        private bool lockwh;

        public bool LockWH
        {
            get { return lockwh; }
            set { lockwh = value; OnPropertyChanged(); }
        }

        public class ReSizeTemp
        {
            public ReSizeTemp(string temp)
            {
                var find = temp[temp.IndexOf('(')..].TrimStart('(').TrimEnd(')');
                Width = int.Parse(find.Split('x')[0]);
                Height = int.Parse(find.Split('x')[1]);
                ShowStr = temp;
            }
            public int Width { get; set; }
            public int Height { get; set; }
            public string ShowStr { get; set; }
        }

        public override MagickImage CalImages(MagickImage input)
        {
            throw new NotImplementedException();
        }
    }
    public class Func_WaterMarkText : Func_Base
    {
        public Func_WaterMarkText() : base("文字水印")
        {
            waterMarkText = "";
            waterMarkSize = 20;
            waterMarkFontType = "微软雅黑";
            waterMarkColor = "#FF0000";
            waterMarkPosition = "0,0,0,0";

        }
        private string waterMarkText;

        public string WaterMarkText
        {
            get { return waterMarkText; }
            set { waterMarkText = value; OnPropertyChanged(); }
        }
        private int waterMarkSize;
        public int WaterMarkSize
        {
            get { return waterMarkSize; }
            set { waterMarkSize = value; OnPropertyChanged(); }
        }
        private string waterMarkColor;
        public string WaterMarkColor
        {
            get { return waterMarkColor; }
            set { waterMarkColor = value; OnPropertyChanged(); }
        }
        private string waterMarkPosition;
        public string WaterMarkPosition
        {
            get { return waterMarkPosition; }
            set { waterMarkPosition = value; OnPropertyChanged(); }
        }
        private string waterMarkFontType;

        public string WaterMarkFontType
        {
            get { return waterMarkFontType; }
            set { waterMarkFontType = value; OnPropertyChanged(); }
        }
        public override MagickImage CalImages(MagickImage input)
        {
            return input;
        }
    }

    public class Func_WaterMarkImage : Func_Base
    {
        public Func_WaterMarkImage() : base("图片水印")
        {
            waterMarkImagePath = "";
            waterMarkPosition = "0,0,0,0";
        }
        private string waterMarkImagePath;
        public string WaterMarkImagePath
        {
            get { return waterMarkImagePath; }
            set { waterMarkImagePath = value; OnPropertyChanged(); }
        }
        private string waterMarkPosition;
        public string WaterMarkPosition
        {
            get { return waterMarkPosition; }
            set { waterMarkPosition = value; OnPropertyChanged(); }
        }
        public override MagickImage CalImages(MagickImage input)
        {
            return input;
        }
    }

    public class Func_Compress : Func_Base
    {
        public Func_Compress() : base("压缩图片")
        {
            compressQuality = 80;
        }
        private int compressQuality;
        public int CompressQuality
        {
            get { return compressQuality; }
            set { compressQuality = value; OnPropertyChanged(); }
        }
        public override MagickImage CalImages(MagickImage input)
        {
            return input;
        }
    }
    public class Func_Rotate : Func_Base
    {
        public Func_Rotate() : base("旋转图片")
        {
            rotateAngle = 0;
        }
        private int rotateAngle;
        public int RotateAngle
        {
            get { return rotateAngle; }
            set { rotateAngle = value; OnPropertyChanged(); }
        }
        public override MagickImage CalImages(MagickImage input)
        {
            return input;
        }
    }
    public class Func_Border : Func_Base
    {
        public Func_Border() : base("添加边框")
        {
            brightnessValue = 0;
        }
        private int brightnessValue;
        public int BrightnessValue
        {
            get { return brightnessValue; }
            set { brightnessValue = value; OnPropertyChanged(); }
        }

        private string cornerradius;

        public string CornerRadius
        {
            get { return cornerradius; }
            set { cornerradius = value; OnPropertyChanged(); }
        }
        public override MagickImage CalImages(MagickImage input)
        {
            return input;
        }
    }

    public class Func_Mirro : Func_Base
    {
        public Func_Mirro() : base("镜像")
        {
            contrastValue = 0;
        }
        private int contrastValue;
        public int ContrastValue
        {
            get { return contrastValue; }
            set { contrastValue = value; OnPropertyChanged(); }
        }
        public override MagickImage CalImages(MagickImage input)
        {
            return input;
        }
    }

    public class Func_Saturation : Func_Base
    {
        public Func_Saturation() : base("调整饱和度")
        {
            saturationValue = 0;
        }
        private int saturationValue;
        public int SaturationValue
        {
            get { return saturationValue; }
            set { saturationValue = value; OnPropertyChanged(); }
        }
        public override MagickImage CalImages(MagickImage input)
        {
            return input;
        }
    }

    public class Func_Sharpness : Func_Base
    {
        public Func_Sharpness() : base("调整锐度")
        {
            sharpnessValue = 0;
        }
        private int sharpnessValue;
        public int SharpnessValue
        {
            get { return sharpnessValue; }
            set { sharpnessValue = value; OnPropertyChanged(); }
        }
        public override MagickImage CalImages(MagickImage input)
        {
            return input;
        }
    }

    public class Func_Blur : Func_Base
    {
        public Func_Blur() : base("模糊图片")
        {
            blurValue = 0;
        }
        private int blurValue;
        public int BlurValue
        {
            get { return blurValue; }
            set { blurValue = value; OnPropertyChanged(); }
        }
        public override MagickImage CalImages(MagickImage input)
        {
            return input;
        }
    }

    public class Func_Pixelate : Func_Base
    {
        public Func_Pixelate() : base("马赛克")
        {
            pixelateValue = 0;
        }
        private int pixelateValue;
        public int PixelateValue
        {
            get { return pixelateValue; }
            set { pixelateValue = value; OnPropertyChanged(); }
        }
        public override MagickImage CalImages(MagickImage input)
        {
            return input;
        }
    }



}
